﻿using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Web.Security;
using webapp4U;
using webapp4U.BOL;

namespace webapp4U.UI
{
    [ParseChildren(true)]
    public class ddlRaovatCategory : DropDownList
    {
        public ddlRaovatCategory()
        {
            this.Items.Insert(0, new ListItem(ResourceManager.GetString("PleaseSelect"), ""));
            List<webapp4U.BOL.Category> rootCategory = webapp4U.BOL.Category.GetCategoryByParentCateID((int)eCategory.Raovat); // get root level ones
            if (rootCategory.Count > 0)
            {
                foreach (webapp4U.BOL.Category c in rootCategory)
                {
                    string strTree = "   ";
                    this.CssClass = "dropdownlistParent";
                    ListItem l = new ListItem(strTree + ((Globals.LangVietNam()) ? c.CateName : c.CateName_en), c.CateID.ToString());
                    l.Attributes.Add("style", "font-weight:Bold;");
                    this.Items.Add(l);
                    populateCategoryAdd(c.CateID);
                }
            }
        }

        private void populateCategoryAdd(int ParentCateID)
        {
            string strTree = "    |--";
            List<webapp4U.BOL.Category> rootCategory = webapp4U.BOL.Category.GetCategoryByParentCateID(ParentCateID); // get root level ones
            foreach (webapp4U.BOL.Category c in rootCategory)
            {
                ListItem l = new ListItem(strTree + ((Globals.LangVietNam()) ? c.CateName : c.CateName_en), c.CateID.ToString());
                //l.Attributes.Add("style", "color:Blue;");
                this.Items.Add(l);
                //this.Items.Add(new ListItem(strTree + c.CateName, c.CateID.ToString()));
                populateCategoryAdd2(c.CateID);
            }
        }

        private void populateCategoryAdd2(int ParentCateID)
        {
            string strTree = "      ";
            List<webapp4U.BOL.Category> rootCategory = webapp4U.BOL.Category.GetCategoryByParentCateID(ParentCateID); // get root level ones
            foreach (webapp4U.BOL.Category c in rootCategory)
            {
                ListItem l = new ListItem(strTree + ((Globals.LangVietNam()) ? c.CateName : c.CateName_en) , c.CateID.ToString());
                //l.Attributes.Add("style", "color:Blue;");
                this.Items.Add(l);
                //this.Items.Add(new ListItem(strTree + c.CateName, c.CateID.ToString()));
                populateCategoryAdd2(c.CateID);
            }
        }

    }
}
